package com.yungu.swift.order.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.miemiedev.mybatis.paginator.domain.PageBounds;
import com.github.miemiedev.mybatis.paginator.domain.PageList;
import com.yungu.swift.base.ResponseData;
import com.yungu.swift.base.model.PageVo;
import com.yungu.swift.order.dao.OrderCallHistoryMapper;
import com.yungu.swift.order.model.dto.OrderCallHistoryDto;
import com.yungu.swift.order.model.param.AdminCallOrderPageParam;
import com.yungu.swift.order.service.OrderCallHistoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.beans.BeanMap;


/**
 * OrderCallHistoryServiceImpl
 **/

@Service
public class OrderCallHistoryServiceImpl implements OrderCallHistoryService {

    @Autowired
    private OrderCallHistoryMapper orderCallHistoryMapper;

    @Override
    public ResponseData<Boolean> close(String uuid, String sysUserUuid) {
        if (orderCallHistoryMapper.close(uuid, sysUserUuid) > 0) {
            return ResponseData.buildSuccessResponse("操作成功，通话已关闭", Boolean.TRUE);
        }
        return ResponseData.buildErrorResponse(ResponseData.ERROR_CODE, "操作失败，记录未更新");
    }

    @Override
    public ResponseData<PageVo<OrderCallHistoryDto>> queryPage(AdminCallOrderPageParam callOrderPageParam) {
        PageBounds pageBounds = new PageBounds(callOrderPageParam.getPageNum(), callOrderPageParam.getPageSize());
        PageList<OrderCallHistoryDto> pageList = orderCallHistoryMapper.queryPage(BeanMap.create(callOrderPageParam), pageBounds);
        PageVo<OrderCallHistoryDto> pageVo = new PageVo(callOrderPageParam.getPageNum(), callOrderPageParam.getPageSize(),
                pageList.getPaginator().getTotalCount());
        pageVo.setItems(pageList);
        return ResponseData.buildSuccessResponse(pageVo);
    }
}